﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("YUIAspNet");

YUIAspNet.SimpleEditor = function(element) {
    YUIAspNet.SimpleEditor.initializeBase(this, [element]);
}

YUIAspNet.SimpleEditor.prototype = {
    initialize: function() {
        YUIAspNet.SimpleEditor.callBaseMethod(this, 'initialize');
    },

    initializeYUIControl: function(sender, args) {

        //The SimpleEditor config 
        var config = {
            dompath: this.get_ShowDomPath(),
            insert: this.get_RequireSelection(),
            extracss: this.get_ExtraCss(),
            focusAtStart: this.get_FocusAtStart(),
            maxUndo: this.get_MaxUndo(),
            plainText: this.get_PreserveInitialFormat(),
            ptags: this.get_UseParagraph()
        };

        if (this.get_Height())
            config.height = this.get_Height();
        else
            config.autoHeight = true;

        if (this.get_Width())
            config.width = this.get_Width();

        config.disabled = !this.get_Enabled();

        this._yuiControl = new YAHOO.widget.SimpleEditor(this.get_InputID(), config);
        var editor = this._yuiControl;
        this._yuiControl.on("editorKeyPress", function() { editor.saveHTML(); }, editor, null);

        //auto sync
        //this._yuiControl.on("focus", function() { alert("lost focus") });
        //this._yuiControl.saveHTML();

        this._yuiControl.render();
    },

    get_ShowDomPath: function() {
        return this._showDomPath;
    },
    set_ShowDomPath: function(showDomPath) {
        this._showDomPath = showDomPath;
    },

    get_FocusAtStart: function() {
        return this._focusAtStart;
    },
    set_FocusAtStart: function(focusAtStart) {
        this._focusAtStart = focusAtStart;
    },

    get_UseParagraph: function() {
        return this._useParagraph;
    },
    set_UseParagraph: function(useParagraph) {
        this._useParagraph = useParagraph;
    },

    get_PreserveInitialFormat: function() {
        return this._preserveInitialFormat;
    },
    set_PreserveInitialFormat: function(preserveInitialFormat) {
        this._preserveInitialFormat = preserveInitialFormat;
    },

    get_RequireSelection: function() {
        return this._requireSelection;
    },
    set_RequireSelection: function(requireSelection) {
        this._requireSelection = requireSelection;
    },

    get_ExtraCss: function() {
        return this._extraCss;
    },
    set_ExtraCss: function(extraCss) {
        this._extraCss = extraCss;
    },

    get_MaxUndo: function() {
        return this._maxUndo;
    },
    set_MaxUndo: function(maxUndo) {
        this._maxUndo = maxUndo;
    },

    get_Width: function() {
        return this._width;
    },
    set_Width: function(width) {
        this._width = width;
    },

    get_Height: function() {
        return this._height;
    },
    set_Height: function(height) {
        this._height = height;
    },

    get_InputID: function() {
        return this._inputID;
    },
    set_InputID: function(inputID) {
        this._inputID = inputID;
    },

    get_Enabled: function() {
        return this._enabled;
    },
    set_Enabled: function(enabled) {
        this._enabled = enabled;
    }
}

YUIAspNet.SimpleEditor.registerClass('YUIAspNet.SimpleEditor', YUIAspNet.BaseControl);
